package handlers

import (
	"encoding/json"
	"io"
	"net/http"
	"video_server/api/defs"
)

// SendErrorResponse 发生错误消息
func SendErrorResponse(w http.ResponseWriter, errResp defs.ErrResponse) {
	w.WriteHeader(errResp.HttpSC)

	// 序列化
	// 将数据编码成json字符串
	resStr, _ := json.Marshal(&errResp.Error)

	// 写入流，也就是把 reStr 写入 http.ResponseWriter
	io.WriteString(w, string(resStr))
}

// SendNormalResponse 发送成功消息
func SendNormalResponse(w http.ResponseWriter, resp string, sc int) {
	w.WriteHeader(sc)
	io.WriteString(w, resp)
}
